/**
 * @Author: 陈瑞鹏
 * @Date:   2023-01-29 11:31:22
 * @Last Modified by:   陈瑞鹏
 * @Last Modified time: 2023-02-01 14:17:47
 */
import gameCtr from "../ctrs/gameCtr";
import helpCtr from "../ctrs/helps/helpCtr";
import BaseGameLayer from "../libs/core/BaseGameLayer";
import { SceneManager } from "../libs/manager/SceneManager";
import { gameConfig } from "../shared/game/gameConfig";
import tipLayer from "./tipLayer";
const { ccclass, property } = cc._decorator;
@ccclass
export default class helpLayer extends BaseGameLayer {

  public helpEntityArr = [];

  onEnable(): void {
    super.onEnable();
    this.helpEntityArr = helpCtr.ins.getThreeEntity();
    this.drawUI(this.helpEntityArr)
  }

  drawUI(arr) {
    arr.forEach((element, i) => {
      if (element)
        this.node.getChildByName("item" + (i + 1)).getChildByName("desc").getComponent(cc.Label).string = element.desc;
    });
  }

  /**
   * 点击选择
   * @param e 
   * @param key 
   */
  onItemClick(e: cc.Event, key) {
    for (let i = 1; i <= 3; i++) {
      this.node.getChildByName("item" + i).getChildByName("isSelect").active = false;
    }
    this.node.getChildByName("item" + key).getChildByName("isSelect").active = true;
    helpCtr.ins.curHelpEntity = this.helpEntityArr[Number(key) - 1];

  }

  onTouchUI(e: cc.Event, switchKey: string): void {
    super.onTouchUI(e, switchKey);
    for (let i = 1; i <= 3; i++) {
      this.node.getChildByName("item" + i).getChildByName("isSelect").active = false;
    }
    gameCtr.ins.curScene.emit("onHelpClick");
  }
}